package com.chf.job.service.impl;

import com.chf.job.dao.HopeJobMapper;
import com.chf.job.pojo.HopeJob;
import com.chf.job.service.HopeJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HopeJobServiceImpl implements HopeJobService {
    @Autowired
    private HopeJobMapper hopeJobMapper;

    /**
     * 添加期望工作
     * @return
     */
    @Override
    public int updateHopeJob(HopeJob hopeJob) {
        HopeJob oleHopeJob = hopeJobMapper.selectByResumeId(hopeJob.getResumeId());
        if (oleHopeJob == null) {
            HopeJob newHopeJob = new HopeJob();
            newHopeJob.setHopeCity(hopeJob.getHopeCity());
            newHopeJob.setMonthSalary(hopeJob.getMonthSalary());
            newHopeJob.setResumeId(hopeJob.getResumeId());
            newHopeJob.setNatureForJob(hopeJob.getNatureForJob());
            newHopeJob.setPositionDesired(hopeJob.getPositionDesired());
            return hopeJobMapper.insertSelective(newHopeJob);
        }
        HopeJob newHopeJob = new HopeJob();
        newHopeJob.setHopeCity(hopeJob.getHopeCity());
        newHopeJob.setMonthSalary(hopeJob.getMonthSalary());
        newHopeJob.setResumeId(hopeJob.getResumeId());
        newHopeJob.setNatureForJob(hopeJob.getNatureForJob());
        newHopeJob.setPositionDesired(hopeJob.getPositionDesired());
        return hopeJobMapper.updateByPrimaryKeySelective(newHopeJob);
    }

    /**
     * 根据简历id查询期望工作
     * @param id
     * @return
     */
    @Override
    public HopeJob getById(Integer id) {
        return hopeJobMapper.selectByResumeId(id);
    }
}
